package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.Result;
import io.renren.dao.AuxiliaryMaterialsmxDao;
import io.renren.dto.AuxiliaryMaterialsmxDTO;
import io.renren.entity.AuxiliaryMaterialsmxEntity;
import io.renren.service.AuxiliaryMaterialsmxService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 辅材采购明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@Service
public class AuxiliaryMaterialsmxServiceImpl extends CrudServiceImpl<AuxiliaryMaterialsmxDao, AuxiliaryMaterialsmxEntity, AuxiliaryMaterialsmxDTO> implements AuxiliaryMaterialsmxService {
    @Autowired
    private AuxiliaryMaterialsmxDao materialsmxDao;
    @Autowired
    private AuxiliaryMaterialsmxDao auxiliaryMaterialsmxDao;
    @Override
    public QueryWrapper<AuxiliaryMaterialsmxEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AuxiliaryMaterialsmxEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public void deleteOrder(Long dto) {
         materialsmxDao.deleteOrder(dto);
    }
    @Override
    public List<AuxiliaryMaterialsmxDTO> selectGyss(Long id) {
        return auxiliaryMaterialsmxDao.seletGys(id);
    }

    @Override
    public List<AuxiliaryMaterialsmxDTO> seletMx(Long id) {
        return auxiliaryMaterialsmxDao.seletMx(id);
    }

    @Override
    public List<AuxiliaryMaterialsmxDTO> selectFoods(long id,long ids) {
        return auxiliaryMaterialsmxDao.seletGysFood(id,ids);
    }

    @Override
    public List<AuxiliaryMaterialsmxDTO> seletGysFood1(long id, long ids) {
        return auxiliaryMaterialsmxDao.seletGysFood1(id,ids);
    }

    @Override
    public void updateUnitPrice(AuxiliaryMaterialsmxDTO dto){
      /* if(dto.getStatus()==1){
           dto.setStatus(3);

       }*/
      dto.setSubStatus(1);
       update(dto);

   }

    @Override
    public  Result updatePhoto(AuxiliaryMaterialsmxDTO dto){
        AuxiliaryMaterialsmxDTO materialsmxDTO = auxiliaryMaterialsmxDao.gysMx(dto.getAuxiliaryMaterialsmxId());
        if(0 != materialsmxDTO.getSubStatus()){
            dto.setStatus(4);
            dto.setSubStatus(1);
            update(dto);
            return new Result();
        }else {
            Result result = new Result();
            result.setMsg("供应商未报价，不能审核");
            result.setCode(5000);
            return result;
        }
    }

    @Override
    public void updateOrder1(long id, long subStutas) {
        auxiliaryMaterialsmxDao.updateOrder1(id,subStutas);
    }

    @Override
    public void updateOrder2(long orderId, long foodId, float purchaseNum) {
        auxiliaryMaterialsmxDao.updateOrder2(orderId, foodId,purchaseNum);
    }

    @Override
    public void delectOrder(long orderId, long foodId) {
        auxiliaryMaterialsmxDao.delectOrder1(orderId,foodId);
    }
}